
Ext.namespace("Ext.milan.pagejs.page_sysYg");
Ext.milan.pagejs.page_sysYg.userWin = null;
Ext.milan.pagejs.page_sysYg.subWin = null;
Ext.milan.pagejs.page_sysYg.REQUEST_ACTION = "employe";
var selectPostionTree = null;
Ext.milan.pagejs.page_sysYg.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.page_sysYg.docOnReadyCallback = function() {

};

/**
 * 关闭子弹出窗口
 */
Ext.milan.pagejs.page_sysYg.closeSubWin = function() {
	Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_sysYg.subWin);
};

/**
 * 关闭弹出窗口
 */
Ext.milan.pagejs.page_sysYg.closeWin = function(winName) {
	if(winName){
		if(winName=='inactivateConsignerWin')
			inactivateConsignerWin.closeDialog();
	}
	else
		Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_sysYg.userWin);
};

/*------------------------ private methods -----------------------*/

/**
 * 查询所有
 */
Ext.milan.pagejs.page_sysYg._search = function() {
	Ext.milan.pagejs.common_utils.query(false, "sysYg/list.do");
};

Ext.milan.pagejs.page_sysYg._formCheck = function(frm) {
	function focusElement(el) {
		if(el.focus)
			el.focus();
	};
	return true;
};

Ext.milan.pagejs.page_sysYg._formCheckRydd = function(frm) {
	function focusElement(el) {
		if(el.focus)
			el.focus();
	};
	return true;
};

/**
 * 保存信息
 */
Ext.milan.pagejs.page_sysYg._saveInfo = function(formId) {
	if(!Ext.milan.pagejs.page_sysYg._formCheck($(formId)))
		return;
		
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_sysYg.closeWin();
			Ext.milan.pagejs.page_sysYg.query();
		}
	});
};


/**
 * 条件查询列表
 */
Ext.milan.pagejs.page_sysYg.query = function() {
	Milan.pagejs.page_index.updateCurrentTabByForm("query_sysYg_list_form");
};

/**
 * 显示新建表单
 */
Ext.milan.pagejs.page_sysYg.showAddForm = function() {
	var url = Ext.milan.pagejs.page_sysYg.REQUEST_ACTION + "/create.do";
	Ext.milan.pagejs.page_sysYg.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:650
	});
};

/**
 * 显示新建表单
 */
Ext.milan.pagejs.page_sysYg.showAddRyddForm = function(formId) {
	var ygids = "";
	var formEle = $(formId);
	var types = formEle.ygids;
	var selCount=0;
	if (types!=null)
	{
		if (types.length!= null) 
		{
			for (i = 0; i < types.length; i++) 
			{
				if (types[i].checked){
					ygids += types[i].value+",";
					selCount++;
				}
			}
		}
		else 
		{
			if (types.checked){
				ygids = types.value;
				selCount++;
			}
		}
	}
	if(ygids != ''){
		ygids = ygids.substring(0,ygids.length-1);
	}
	if(selCount > 0){
		var url = Ext.milan.pagejs.page_sysYg.REQUEST_ACTION + "/ryddCreate.do?ygids="+ygids;
		Ext.milan.pagejs.page_sysYg.userWin = Milan.commonutils.createModelPop({
			title:"新建", 
			url:url,
			width:650
		});
	}else{
		Milan.commonutils.createDelayNotifyModel('提示信息',"请选择员工！");
	}
};

Ext.milan.pagejs.page_sysYg.saveRydd = function(formId) {
	if(!Ext.milan.pagejs.page_sysYg._formCheckRydd($(formId)))
		return;
		
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_sysYg.closeWin();
			Milan.pagejs.page_index.updateCurrentTabByForm("query_sysYg_list_rydd_form");
		}
	});
};

/**
 * 显示编辑表单
 * 
 * @param ID
 */
Ext.milan.pagejs.page_sysYg.showEditForm = function(id) {
	var url = Ext.milan.pagejs.page_sysYg.REQUEST_ACTION + "/edit.do?ygbh=" + id;
	Ext.milan.pagejs.page_sysYg.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:650
	});
};

/**
 * 保存新建用户信息
 */
Ext.milan.pagejs.page_sysYg.save = function(formId) {
	Ext.milan.pagejs.page_sysYg._saveInfo(formId);
};

/**
 * 保存编辑后的信息
 */
Ext.milan.pagejs.page_sysYg.edit = function(formId) {
	Ext.milan.pagejs.page_sysYg._saveInfo(formId);
};

Ext.milan.pagejs.page_sysYg.deleteForm = function(id) {
	var url = Ext.milan.pagejs.page_sysYg.REQUEST_ACTION + "/delete.do?ygbh=" + id;
	new Milan.widget.ConfirmDialog("确认信息", "确认要删除该信息吗？", {
		confirmCallback: function() {
			Milan.ajaxutility.formSubmit({
				url: url,
				method: 'post',
				success: function(response, option)
				{
					Ext.milan.pagejs.page_sysYg.query();
				}
			});
		}
	});	
};

/**
 * 查看详情
 * 
 * @param entityId 用户ID
 */
Ext.milan.pagejs.page_sysYg.viewDetail = function(entityId) {
	var url = Ext.milan.pagejs.page_sysYg.REQUEST_ACTION + "/show.do?ygbh=" + entityId;
	Ext.milan.pagejs.page_sysYg.userWin = Milan.commonutils.createModelPop({
		title:"详细信息",
		url:url,
		width:500
	});
};

/**
 * 显示“选择部门”弹出框
 */
Ext.milan.pagejs.page_sysYg.showSelectDeptWin = function(formId) {
	new Milan.widget.Selector({
		orgType:"32",
		title:"部门选择",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"dept/quickSelectDept.do?",
		searchUrl:"dept/selectDeptByDeptid.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false
	},
	false,
	{
		onSelectedCallBack : function(arr)
		{
	 		if (arr!=null)
	    	{
			    var form = $(formId);
			    document.getElementById('_dept_of_add_wf').innerHTML = arr[0].name;
		        form.deptid.value = arr[0].deptid;
			}
		}
	});
};
